package com.smsc.headend.task.engine.controller;

import cn.hutool.json.JSONUtil;
import com.smsc.headend.task.engine.service.dds.ScheduleDdsService;
import com.smsc.headend.task.engine.service.task.TaskService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import java.util.Set;
import java.util.concurrent.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;

@Slf4j
@Component
public class TaskController {

    @Autowired
    ScheduleDdsService scheduleDdsService;
    private ScheduledExecutorService ddsService = Executors.newSingleThreadScheduledExecutor();

    @PostConstruct
    public void init() {
        log.info("init TaskController");
        this.start();
    }

    public void start() {
        //DDS上传
        this.ddsService.scheduleAtFixedRate(() -> {
            try {
                scheduleDdsService.quartzUploadFile();
            } catch (Exception e) {
                log.error("quartzUploadFile error", e);
            }
        }, 0, 5 * 60 * 1000, TimeUnit.MILLISECONDS);
    }





    @PreDestroy
    public void shutdown() {
        log.info("shutting down executors");
        try {
            this.ddsService.shutdown();
        } catch (Exception e) {
            log.info("shutting down exception", e);
        }
    }
}

